/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package daw.listener;

import com.griaule.grfingerjava.GrFingerJava;
import com.griaule.grfingerjava.MatchingContext;
import java.io.File;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * Web application lifecycle listener.
 * @author Christian
 */

public class InicializarLectorDeHuellas implements ServletContextListener {

    public void contextInitialized(ServletContextEvent arg0) {
        String url = arg0.getServletContext().getRealPath("/libs/grfinger/bin");
        Integer n = (Integer)arg0.getServletContext().getAttribute("n");
        if(n == null){
            n = 0;
        }

       try{
            n = n+1;
            System.out.println("************************************************");
            System.out.println("*********** EJECUTADO "+n+" VECES ******************");
            System.out.println("************************************************");
            arg0.getServletContext().setAttribute("n", n);
            GrFingerJava.setNativeLibrariesDirectory(new File(url));
            GrFingerJava.setLicenseDirectory(new File(url));

            if(arg0.getServletContext().getAttribute("contextoHuella") == null){
                MatchingContext contexto = new MatchingContext();
                arg0.getServletContext().setAttribute("contextoHuella", contexto);
            }

        }catch(Exception ex){
            System.out.print(ex);
        }catch(Throwable e){
            System.out.println(e);
        }
    }

    public void contextDestroyed(ServletContextEvent arg0) {}
}